package com.service.impl;

import java.util.*;

import javax.annotation.Resource;

import com.beans.User;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.beans.Admin;
import com.mapper.AdminMapper;
import com.service.AdminService;
import org.springframework.util.StringUtils;

@Service
@Transactional
public class AdminServiceImpl implements AdminService {
    @Resource
    private AdminMapper adminMapper;

    public List<Admin> getone(String AdminName) {
        return adminMapper.getone(AdminName);
    }

    @Override
    public Map<String, Object> queryByPage(Admin admin, Integer page, Integer limit) {
        Map<String, Object> resMap = new HashMap<>(4);
        PageHelper.offsetPage((page - 1) * limit, limit);
        List<Admin> dataList = Collections.EMPTY_LIST;
        if(StringUtils.hasText(admin.getUserName())){
            dataList = adminMapper.getone(admin.getUserName());
        }else{
            dataList = adminMapper.getAllAdmin();
        }
        PageInfo<Admin> pageInfo = new PageInfo<>(dataList);
        resMap.put("code", 0);
        resMap.put("msg", "查询成功");
        resMap.put("data", pageInfo.getList());
        resMap.put("count", pageInfo.getTotal());
        return resMap;
    }

    public int addAdmin(Admin Admin) {
        return adminMapper.addAdmin(Admin);
    }

    public int deleteAdmin(int id) {
        return adminMapper.deleteAdmin(id);
    }

    public Admin getAdminById(int id) {
        return adminMapper.getAdminById(id);
    }

    public List<Admin> getAllAdmin() {
        return adminMapper.getAllAdmin();
    }

    public int updateAdmin(Admin Admin) {
        return adminMapper.updateAdmin(Admin);
    }
}


